package argtrust.gui;

import javax.swing.JFrame;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import com.mxgraph.model.mxIGraphModel;

public class HelloWorldAPITesting extends JFrame {

    /**
     *
     */
    private static final long serialVersionUID = -2707712944901661771L;

    public HelloWorldAPITesting() {
        super("Hello, World!");

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();

        graph.getModel().beginUpdate();
        try {
            graph.enterGroup();
            Object v1 = graph.insertVertex(graph.getDefaultParent(), null, "Hello1", 20, 20, 200,
                    130);
            graph.updateCellSize(v1);
            Object v2 = graph.insertVertex(graph.getDefaultParent(), null, "World1!", 240, 150,
                    80, 30);
            graph.updateCellSize(v2);
            graph.insertEdge(graph.getDefaultParent(), null, "Edge1", v1, v2);
            graph.exitGroup();

            graph.enterGroup();
            Object vv1 = graph.insertVertex(graph.getDefaultParent(), null, "Hello", 20, 20, 80,
                    30);
            graph.updateCellSize(vv1);
            Object vv2 = graph.insertVertex(graph.getDefaultParent(), null, "World!", 240, 80,
                    80, 30);
            graph.updateCellSize(vv2);
            graph.insertEdge(graph.getDefaultParent(), null, "Edge2", vv1, vv2);
            graph.exitGroup();
//            graph.groupCells(sub_graph);
//            graph.groupCells(sub_graph0);


            graph.insertEdge(parent, null, "Edge", v1, vv2);


//            cells = graph.getChildCells(parent);
//            for (int i = 0; i < cells.length; i++) {
//                graph.updateCellSize(cells[i], false);
//            }


            com.mxgraph.layout.mxIGraphLayout layout = new com.mxgraph.layout.mxCircleLayout(graph);
            layout.execute(parent);
            new com.mxgraph.layout.mxPartitionLayout(graph).execute(parent);


        } finally {
            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        getContentPane().add(graphComponent);




//            new com.mxgraph.layout.mxStackLayout(graph).execute(parent);


    }

    public static void main(String[] args) {
        HelloWorldAPITesting frame = new HelloWorldAPITesting();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }
}
